<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div>
          <el-button type="info" size="mini" @click="$router.go(-1)">返回</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form :model="CheckEdit" :rules="rulesinfo" label-width="100px" label-position="top" :inline="true" size="medium">
          <input type="hidden" v-model="CheckEdit.pk_Car" />
          <el-form-item label="类型" prop="TypeID">
            <el-select v-model="CheckEdit.TypeID" style="width:621px">
             <el-option v-for="(item,index) in TypeList.Type" :key="index" :value="item.ID" :label="item.TypeName_CHS"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="车辆" prop="fk_Set">
            <el-select v-model="CheckEdit.fk_Set" style="width:621px">
             <el-option v-for="(item,index) in TypeList.Set" :key="index" :value="item.pk_Set" :label="item.Title"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="标题" prop="title">
            <el-input placeholder v-model="CheckEdit.Title"></el-input>
          </el-form-item>
          <el-form-item label="司机" prop="Driver">
            <el-input placeholder v-model="CheckEdit.Driver"></el-input>
          </el-form-item>
          <el-form-item label="目的地" prop="Destination">
            <el-input placeholder v-model="CheckEdit.Destination"></el-input>
          </el-form-item>
          <el-form-item label="出发前里程" prop="Mileage">
            <el-input placeholder v-model="CheckEdit.Mileage"></el-input>
          </el-form-item>
          <el-form-item label="开始时间" prop="StartDate">
            <template>
              <el-date-picker v-model="CheckEdit.StartDate" type="datetime" placeholder="选择日期时间" style="width:621px">
              </el-date-picker>
            </template>
          </el-form-item>
          <el-form-item label="结束时间" prop="EndDate">
            <template>
              <el-date-picker v-model="CheckEdit.EndDate" type="datetime" placeholder="选择日期时间" style="width:621px">
              </el-date-picker>
            </template>
          </el-form-item>
          <el-form-item label="用车原因" prop="Description">
            <template>
              <el-input type="textarea" v-model="CheckEdit.Description"></el-input>
            </template>
          </el-form-item>
          <el-form-item label="状态" prop="StatusID">
            <el-select v-model="CheckEdit.StatusID" style="width:621px">
              <el-option v-for="(item,index) in TypeList.Status" :key="index" :value="item.ID" :label="item.StatusName_CHS"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="Note">
            <template>
              <el-input type="textarea" v-model="CheckEdit.Note"></el-input>
            </template>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div>
          <el-button type="primary" size="mini" @click="Update(CheckEdit)" icon="el-icon-check">审核</el-button>
          <el-button type="info" size="mini" icon="el-icon-close">取消</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<style lang="scss" scoped>
.el-row {
  margin-bottom: 10px;
}
.el-form-item {
  width: 49%;
}
</style>
<script>
export default {
  data () {
    return {
      CheckEdit: {
      },
      TypeList:[],
      rulesinfo:{
        StatusID:[
           {required:true,message:'请输入内容',trigger:'blur'}
        ],
        TypeID:[
            {required:true,message:"请输入内容",trigger:'blur'}
        ],
        StartDate:[
          {required: true, message: '请选择日期', trigger: 'change'}
        ],
        EndDate:[
          {required: true, message: '请选择日期', trigger: 'change'}
        ],
        Title:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ],
        Description:[
           {min:1,max:100,message:"长度在1到100之间"}
        ],
        fk_Set:[
            {required:true,message:"请输入内容",trigger:'blur'}
        ],
        Driver:[
          {required: true, message: '请输入内容', trigger: 'change'}
        ],
        Destination:[
          {required: true, message: '请输入内容', trigger: 'change'}
        ],
        Mileage:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ],
        Note:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ]
      }
    };
  },
  mounted(){
      if(Object.keys(this.$route.query).length){
        this.Type = "Edit";
        this.$axios({
        url: "/HrApi/CheckList/GetCheckInfo",
        method: "GET",
        params:{
          id: this.$route.query["id"]
        },
        }).then((res) => {
        if (!res.data.code) {
          this.CheckEdit = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      });
      };
       this.$axios({
          url: '/HrApi/CheckList/GetCheckType',
          method: 'GET'
        }).then(res => {
          this.TypeList = res.data.data
        })

  },
  methods:{
    Update(CheckEdit){
      console.log(this.CheckEdit)
      this.$axios({
          url: "/HrApi/CheckList/Update",
          method: "POST",
          data: this.$Qs.stringify({
            User:this.$store.state.UserInfo.pk_User,

            CheckEdit: JSON.stringify(this.CheckEdit)

          }),
        }).then((res) => {
          if (!res.data.code) { 
              this.$message.success(res.data.msg);
          } else {
            this.$message.error(res.data.msg);
          }
        })
    }
  }
};
</script>